package com.haha.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {
    private  Set<Integer> num = new HashSet<>();
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {

        if(!num.contains(value)){
            return false;
        }
        return true;
    }

    @Override
    public void initialize(ListValue constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
        int[] vals = constraintAnnotation.vals();
        for(int a: vals){
            num.add(a);
        }

    }
}
